package com.eshin.configuration;

import com.eshin.configuration.beanprocessor.CustomBeanFactoryPostProcessor;
import com.eshin.configuration.beanprocessor.CustomBeanPostProcessor;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.SmartApplicationListener;

/**
 * @author Eshin
 * @title: CustomBeanPostProcessListener
 * @projectName pay
 * @date 2019/6/1717:04
 */
public class CustomBeanPostProcessListener implements SmartApplicationListener {


    @Override
    public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
        return  ApplicationPreparedEvent.class.isAssignableFrom(eventType);
    }

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        if (event instanceof ApplicationPreparedEvent) {
            ((ApplicationPreparedEvent) event).getApplicationContext().addBeanFactoryPostProcessor(new CustomBeanFactoryPostProcessor());

            ((ApplicationPreparedEvent) event).getApplicationContext().getBeanFactory().addBeanPostProcessor(new CustomBeanPostProcessor());
        }
    }
}
